/**
 * 
 */
package com.xpec.c4.game.login.async2;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.ms.service.error.ErrorCode;
import com.ms.service.module.account.Account;
import com.xpec.c4.game.login.LoginModule;
import com.xpec.c4.game.login.LoginSender;
import com.xpec.c4.game.login.async.AccountLoginRequestGetAccountData;
import com.xpec.c4.game.utility.GUID;
import com.xpec.c4.service.module.datacenter.player.H5GetPlayerListAsync;

/**
 * @author TW15010
 *
 */
public class CharacterListGetAccountAsync extends DoAfterLoadAccountAsync {
	/** log4j object */
	private static final Log log = LogFactory.getLog(CharacterListGetAccountAsync.class);

	private GUID sessionID;

	@Override
	public void execute() throws Exception {
		// TODO kevin jb verify
		Account account = getLoadAccount();

		if (account == null) {
			LoginSender.sendAccountMessage(sessionID, ErrorCode.ACCOUNT_OTHER_ERROR);
			return;
		}

		// 取得角色列表參數
		AccountLoginRequestGetAccountData data = new AccountLoginRequestGetAccountData();
		data.account = account;
		data.accountID = account.getAccountId();
		data.sessionID = sessionID;
		
		// 透過 async 執行
		H5GetPlayerListAsync getPlayerListAsync = new H5GetPlayerListAsync();
		getPlayerListAsync.setRequestData(data);
		getPlayerListAsync.key = account.getAccountId();

		// 執行
		LoginModule module = (LoginModule) getCurrentModuleServer();
		module.addAsyncCommand(getPlayerListAsync);

		if (log.isInfoEnabled()) {
			log.info(LoginModule.LOGIN_TRACE_LOG_STRING + " get PlayerList from redis, a: " + data.accountID);
		}
	}

	public void setSessionID(GUID sessionID) {
		this.sessionID = sessionID;
	}
}
